<!--
 * @Author: ljc
 * @Date: 2023-06-27 13:47:01
 * @LastEditors: g05047
 * @LastEditTime: 2023-06-27 17:41:33
 * @Description: 首页界面
-->
<template>
	<div v-if="openRequestServer" class="home-wrapper" v-loading="loading">
		<component
			v-if="HomeModulesMap[useInfo.roleId]"
			:is="HomeModulesMap[useInfo.roleId] || HomeIndex"
			:taskData="taskData"
			:loading="loading"
			:todoData="todoData"
		>
		</component>
	</div>
	<HomeIndex v-else />
</template>

<script setup name="HomeView">
import { ref, defineAsyncComponent } from 'vue';
import { useHomeApi } from '@/api';
import { useUserStore, useSystemStore } from '@/stores/modules';
import { HomeModulesMap } from './panel/index';
const HomeIndex = defineAsyncComponent(() => import('./index.vue'));

const { openRequestServer } = useSystemStore();

const { getWaitDealTask } = useHomeApi();

let taskData = ref({});
let loading = ref(false);
const useInfo = useUserStore().userInfo;
const todoData = ref({});
const loadWaitDealTask = async () => {
	const resultData = await getWaitDealTaskData();
	todoData.value = resultData;
};
const getWaitDealTaskData = () => {
	loading.value = true;
	return new Promise((reslove) => {
		getWaitDealTask()
			.then((res) => {
				const { data, code, msg } = res;
				if (code === 200) {
					reslove(data);
				} else {
					reslove({});
				}
			})
			.catch((err) => {
				reslove({});
			})
			.finally(() => {
				loading.value = false;
			});
	});
};
if (openRequestServer) {
	loadWaitDealTask();
}
</script>

<style lang="scss" scoped></style>
